<template>
  <div class="detail_content">
    <p class="title">| 基本信息</p>
    <el-row class="base_info">
      <el-col :span="3">
        <span>申请时间:</span>
      </el-col>
      <el-col :span="9">
        <p>{{detail.createTime}}</p>
      </el-col>
      <el-col :span="3">
        <span>提现类型:</span>
      </el-col>
      <el-col :span="9">
        <p>{{detail.withdrawTypeText}}</p>
        <!-- <p v-if="detail.withdraw_type == 5">银行账户</p> -->
      </el-col>
    </el-row>
    <el-row class="base_info">
      <el-col :span="3">
        <span>提现账号:</span>
      </el-col>
      <el-col :span="9">
        <p>{{detail.withdrawAccount}}</p>
      </el-col>
      <el-col :span="3">
        <span>所属小店:</span>
      </el-col>
      <el-col :span="9">
        <p>{{detail.memberName}}</p>
      </el-col>
    </el-row>

    <el-row class="base_info">
      <el-col :span="3">
        <span>申请人账号:</span>
      </el-col>
      <el-col :span="9">
        <p>{{detail.memberMobile}}</p>
      </el-col>
    </el-row>

    <p class="title">| 提现信息</p>
    <div class="order_info">
      <el-table
        :data="tableData"
        style="width:100%"
        max-height="680"
        :cell-style="tc"
        :header-cell-style="tccolor"
      >
        <el-table-column label="UID" prop="id"></el-table-column>
        <el-table-column label="提现金额" prop="money"></el-table-column>
        <el-table-column label="代扣税率" >
          <template slot-scope="scope">
            {{scope.row.rate * 100}}%
          </template>
        </el-table-column>
        <el-table-column label="到账金额" prop="true_money"></el-table-column>
        <el-table-column label="手续费" prop="premiumAmount"></el-table-column>
      </el-table>
    </div>

    <p class="title">| 审核设置</p>

    <el-row class="edit_setting" v-if='isSelect==true'>
      <el-col :span="8">
        <el-radio disabled v-model="status" label="1">
          <i>审核通过，允许提现</i>
        </el-radio>
      </el-col>
      <el-col :span="4">
        <el-radio  disabled v-model="status" label="2">
          <i>审核驳回</i>
        </el-radio>
      </el-col>
      <el-col :span="8">
        <el-input  size="mini" disbled v-model="reason" placeholder="请输入驳回理由"></el-input>
      </el-col>
    </el-row>


    <template v-else>
      <el-row class="edit_setting">
        <el-col :span="8">
          <el-radio  v-model="status" label="1">
            <i>审核通过，允许提现</i>
          </el-radio>
        </el-col>
        <el-col :span="4">
          <el-radio   v-model="status" label="2">
            <i>审核驳回</i>
          </el-radio>
        </el-col>
        <el-col :span="8">
          <el-input  size="mini" v-model="reason" placeholder="请输入驳回理由"></el-input>
        </el-col>
      </el-row>
      <!-- <el-row class="edit_setting" v-if="status=='1'">
        <el-col :span="8">
          <el-radio  v-model="is_company" label="0">
            <i>个人账户，扣税</i>
          </el-radio>
        </el-col>
        <el-col :span="8">
          <el-radio  v-model="is_company" label="1">
            <i>企业账户，不扣税</i>
          </el-radio>
        </el-col>

      </el-row> -->

    </template>

    <div class="class_btn" v-if="isSelect==false">
      <el-button size="mini" type="primary"  @click="CertainWithdrawCancel">确定</el-button>
      <el-button size="mini" type="danager" @click="handleCancel">取消</el-button>
    </div>
  </div>
</template>

<script>
import { withdrawDetails,withdrawOperate } from "@/api/finance";
export default {
  name: "discount_detail",
  props: ["visible", "currentId"],
  data() {
    return {
      status: "",
      reason: "",
      detail: {},
      shop_info: {},
      user_info: {},
      tableData: [],

      isSelect:true,

      //提现
      isClickPassBtn:true,
      is_company: "0"

    };
  },
  watch: {
    visible(newValue) {
      if (newValue) {
        // this.getRecordDetail()
        (this.tableData = []), this.getDiscountDetail();
      }
    }
  },
  methods: {
    tc() {
      return "text-align:center; color:#333333; font-size:12px;";
    },
    tccolor() {
      return "text-align:center;background-color:#f5f5f5; font-size:14px;";
    },
    handleCancel() {
      this.$emit("cancelShow");
    },
    async CertainWithdrawCancel() {
      let data = {
        id: this.detail.id,
        type: this.status,
        reason: this.reason,
        adminId: sessionStorage.getItem("LOGIN_USERNAME_id")
      }
      let res = await withdrawOperate(data);
      if (res.code === 200) {
        this.$message.success(res.message);

        this.handleCancel();
        setTimeout(() => {
          this.isClickPassBtn  = true
        }, 2000);
      } else {
        this.$message.error(res.message);
        setTimeout(() => {
          this.isClickPassBtn  = true
        }, 2000);
      }
      // if (this.status === "1") {

      //   if(this.isClickPassBtn){
      //     this.getWithDrawpass();
      //   }

      // } else if (this.status === "2") {
      //   this.getWithDrawRefuseData();
      // }
    },

    //提现通过
    async getWithDrawpass() {
      this.isClickPassBtn = false
      let res = await withDrawPass({ id: this.currentId, isCompany:this.is_company });
      if (res.code === 10000) {
        this.$message.success("提交成功");

        this.handleCancel();
        setTimeout(() => {
          this.isClickPassBtn  = true
        }, 2000);
      } else {
        this.$message.error(res.message);
        setTimeout(() => {
          this.isClickPassBtn  = true
        }, 2000);
      }
    },

    //提现失败
    // async getWithDrawRefuseData() {
    //   let res = await withDrawRefuse({
    //     id: this.currentId,
    //     reason: this.reason
    //   });
    //   if (res.code === 200) {
    //     this.$message.success("提现审核驳回");
    //   this.handleCancel();
    //   } else {
    //     this.$message.error(res.message);
    //   }
    // },
    async getDiscountDetail() {
      let res = await withdrawDetails(this.currentId);
      if (res.code === 200) {
        this.detail = res.data;
        this.user_info = res.data.user_info;
        this.shop_info = res.data.shop_info;
        if(res.data.reason != 'null'){
           this.reason = res.data.reason;
        }else{
           this.reason = '';
        }

        this.status = res.data.status + "";
        if(this.status !== '1'){
          this.isSelect = true
        }else{
          this.isSelect = false
        }

        // if(this.user_info.alipay_account_is_company == "1") {
        //   this.is_company = "1"
        // } else {
        //   this.is_company = "0"
        // }
        this.tableData.push({
          id: res.data.uid,
          money: res.data.amount,
          true_money: res.data.actualAmount,
          rate:res.data.rate,
          premiumAmount:res.data.premiumAmount
        });
      } else {
        this.$message.error(res.message);
      }
    }
  }
};
</script>


<style scoped lang="scss">
.detail_content {
  padding: 20px;
  .title {
    font-size: 16px;
  }
  i {
    font-size: 12px;
    font-weight: 400;
    color: #333333;
    font-style: normal;
  }
  .base_info {
    margin: 15px 20px 20px;
    span {
      font-size: 12px;
      color: #999999;
    }

    p {
      font-size: 13px;
      color: #333333;
    }
  }
  .order_info {
    margin: 16px 0 20px;
  }

  .class_btn {
    margin-top: 30px;
    text-align: center;
  }

  .edit_setting {
    margin-top: 10px;
  }
}
</style>

